﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLL
{
    /// <summary>
    /// 用户详细表
    /// </summary>
    public class BLL_userinfo
    {
        /// <summary>
        /// 增
        /// </summary>
        /// <param name="ui"></param>
        /// <returns></returns>
        public bool insert(_userinfo ui)
        {
            if (ui._user_email != null)
            {
                GodHelperDBDataContext da = new GodHelperDBDataContext();
                da._userinfo.InsertOnSubmit(ui);
                da.SubmitChanges();
                return true;
            }
            return false;
        }

        /// <summary>
        /// 删
        /// </summary>
        /// <param name="ui"></param>
        /// <returns></returns>
        public bool delete(_userinfo ui)
        {
            GodHelperDBDataContext da = new GodHelperDBDataContext();
            var p = da._userinfo.Where(item => item._user_email == ui._user_email);
            if (p.Any())
            {
                da._userinfo.DeleteOnSubmit(ui);
                da.SubmitChanges();
                return true;
            }
            return false;
        }

        /// <summary>
        /// 改
        /// </summary>
        /// <param name="ui"></param>
        /// <returns></returns>
        public bool update(_userinfo ui )
        {
            GodHelperDBDataContext da = new GodHelperDBDataContext();
            var p = da._userinfo.Where(item => item._user_email == ui._user_email);
            if (p.Any())
            {
                var userinfo = p.ToList()[0];
                userinfo._user_email = ui._user_email;
                userinfo._user_name = ui._user_name;
                userinfo._user_age = ui._user_age;
                userinfo._user_sex = ui._user_sex;
                userinfo._user_qq = ui._user_qq;
                userinfo._user_phone = ui._user_phone;
                userinfo._user_addr = ui._user_addr;
                userinfo._user_ownword = ui._user_ownword;
                userinfo._user_image = ui._user_image;
                da.SubmitChanges();
                return true;
            }
            return false;
        }

        /// <summary>
        /// 查
        /// </summary>
        /// <param name="ui"></param>
        /// <param name="refrenceskey">根据那个键值查询</param>
        /// <returns></returns>
        public _userinfo search(_userinfo ui, string refrenceskey)
        {
            GodHelperDBDataContext da = new GodHelperDBDataContext();
            switch(refrenceskey)
            {
                case "_user_email":
                    if (ui._user_email != null)
                    {
                        var p = da._userinfo.Where(item => item._user_email == ui._user_email);
                        if (p.Any())
                        {
                            return p.ToList()[0];
                        }
                    }
                    break;
                case "_user_name":
                    break;
                case "_user_age":
                    break;
                case "_user_sex":
                    break;
                case "_user_qq":
                    break;
                case "_user_phone":
                    break;
                case "_user_addr":
                    break;
                case "_user_ownword":
                    break;
                case "_user_image":
                    break;
            }
            return null;
        }   
    }
}
